/**
 * 
 */
package deathKitten;

/**
 * @author Adam
 *
 */

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA512Generator {
	
	//Should be changed to byte arrays
	//SHA1 example here
	//http://www.java2s.com/Code/Java/Security/BasicIOexampleusingSHA1.htm
	public String byteArrayToSHA512HashToString (byte input[]) throws NoSuchAlgorithmException, IOException
	{
		MessageDigest md = MessageDigest.getInstance("SHA-512");
		md.reset();
		md.update(input);
		byte[] digest = md.digest();
		
		String hexStr = "";
		for (int i = 0; i < digest.length; i++) {
			hexStr +=  Integer.toString( ( digest[i] & 0xff ) + 0x100, 16).substring( 1 );
		}
		return hexStr;
	}
	
	public byte[] byteArraySHA512HashAsByteArray(byte input[]) throws NoSuchAlgorithmException, IOException
	{
		MessageDigest md = MessageDigest.getInstance("SHA-512");
		md.reset();
		md.update(input);
		return md.digest();
	}

	//this method is finished
	public String textInToSHA512HashString(String input) throws NoSuchAlgorithmException
	{
		MessageDigest md = MessageDigest.getInstance("SHA-512");
		md.reset();
		byte[] buffer = input.getBytes();
		md.update(buffer);
		byte[] digest = md.digest();
	
		String hexStr = "";
		for (int i = 0; i < digest.length; i++) {
			hexStr +=  Integer.toString( ( digest[i] & 0xff ) + 0x100, 16).substring( 1 );
		}
		return hexStr;
	}
	
	public byte[] textInToSHA512HashToByteArray(String input) throws NoSuchAlgorithmException
	{
		MessageDigest md = MessageDigest.getInstance("SHA-512");
		md.reset();
		byte[] buffer = input.getBytes();
		md.update(buffer);
		return md.digest();
	}
}